#!/bin/bash

set -x
set -e

function gMockSample_dynamic()
{

# 1. build gtest libs
(cd gtest && [ -d build ] || mkdir build && cd build && cmake .. && make)

# export LIB and INC of gtest
export GTEST_INC=$(readlink -f gtest/google*/include); export GTEST_LIB=$(readlink -f gtest/build/lib); export GTEST_MAIN=$(readlink -f gtest/googlemock/src/gmock_main.cc)

# build shared lib
mkdir lib; g++ --std=c++14 -pthread -g src/gMockSample.c --shared -fPIC -o lib/libgMockSample.so

# build gtest execution
g++ --std=c++14 -pthread -g -o a.out test/gMockSample_unittest.cpp ${GTEST_MAIN} $(echo ${GTEST_INC} | sed -r 's/([^ ]+)/-I\1/g') -Isrc -L${GTEST_LIB} -lgmock -lgtest -Llib -lgMockSample

# run gtest
LD_LIBRARY_PATH=lib ./a.out

}

git clean -fxd
gMockSample_dynamic
